var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var poststylus = require('poststylus');

module.exports = {
    devtool: 'eval',
    host: '0.0.0.0',
    entry: {
        app: [
            //'webpack-hot-middleware/client',
            './src/index'
        ],
        ui: [
            //'webpack-hot-middleware/client',
            './src/ui.js',
        ],
        auth: [
            //'webpack-hot-middleware/client',
            './src/auth/index'
        ],
        admin: [
            './src/admin/index'
        ],
        charts: [
            './src/charts/index'
        ],
        util: [
            //'webpack-hot-middleware/client',
            './src/utilRoot.js',
        ],
        onboarding: [
            //'webpack-hot-middleware/client',
            './src/onboarding.js',
        ],
        polyfill: [
            'babel-polyfill',
        ]
    },
    output: {
        path: path.join(__dirname, 'static'),
        filename: '[name].js',
        publicPath: '/static/'
    },
    plugins: [
        new ExtractTextPlugin('[name].css', { allChunks: true, disable: false }),
        //new webpack.HotModuleReplacementPlugin(),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
                DEV: JSON.stringify(process.env.DEV || 'production'),
            }
        })
    ],
    externals: [{
        xmlhttprequest:'{XMLHttpRequest:XMLHttpRequest}'
    }],
    resolve: {
        extensions: ['', '.js', '.jsx', '.styl', '.css']
    },
    stylus: {
        use: [
            poststylus([ 'autoprefixer', 'rucksack-css' ])
        ]
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loaders: ['react-hot', 'babel'],
                include: path.join(__dirname, 'src')
            },
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract('style', 'css')
            },
            {
                test: /\.styl$/,
                loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!stylus?sourceMap')
            },
            {
                test   : /\.(ttf|eot|svg|woff)$/,
                loader : 'file-loader'
            },
            {
                test : /\.json$/,
                loader: 'json-loader'
            }
        ]
    }
};
